const Router = require("@koa/router");
const { vertifyToken } = require("../middleware/auth.middleware");
const { warmDelate, warmUpdate } = require("../middleware/warmDelate.middleware");

const {
  create,
  deleted,
  update,
  get,
  getList,
  getPhoto,
  getGoodsCategoryCount,
  getGoodsCategorySale,
  getGoodsCategoryFavor,
  getGoodsAddressSale,
  getGoodsAmountList,
} = require("../controller/goods.controller");

// 创建商品路由实例，设置路由的前缀为 "/goods"
const goodsRouter = new Router({ prefix: "/goods" });

goodsRouter.post("/", vertifyToken, create);  // 创建商品
goodsRouter.delete("/:goodsId", vertifyToken, warmDelate(141), deleted);  // 删除商品
goodsRouter.patch("/:goodsId", vertifyToken, warmUpdate(141), update);  // 更新商品
goodsRouter.get("/:goodsId", vertifyToken, get);  // 获取单个商品信息
goodsRouter.post("/list", vertifyToken, getList);  // 获取商品列表

// 获取商品分类的数量
goodsRouter.get("/category/count", vertifyToken, getGoodsCategoryCount);

// 获取商品分类的销量信息
goodsRouter.get("/category/sale", vertifyToken, getGoodsCategorySale);

// 获取商品分类的收藏信息
goodsRouter.get("/category/favor", vertifyToken, getGoodsCategoryFavor);

// 获取商品销售地址信息
goodsRouter.get("/address/sale", vertifyToken, getGoodsAddressSale);

// 获取商品销售额列表
goodsRouter.get("/amount/list", vertifyToken, getGoodsAmountList);

//根据商品 ID 获取商品对应的照片
goodsRouter.get("/:goodsId/photo", getPhoto);

// 导出商品路由实例
module.exports = goodsRouter;
